home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 213_01 / cr.c < prev    next >
Text File  |  1980-01-01  |  4KB  |  197 lines

  1. /* CR.C        VERS:- 01.00  DATE:- 09/26/86  TIME:- 09:36:24 PM */
  2. /*
  3. %CC1 $1.C -X
  4. %CLINK $1 -N
  5. %DELETE $1.CRL
  6. */
  7. /* 
  8. Description:
  9.  
  10. Opens fname.c, extracts lines with key "%", constructs and runs submit file.
  11. Simplifies compilation and linking in C program development.
  12.  
  13. From Van Nuys Toolkit, by Eugene H. Mallory.
  14. No changes except converted to standard C tokens.
  15.  
  16. By J.A. Rupley, Tucson, Arizona
  17. Coded for BDS C compiler, version 1.50a
  18. */
  19. /*********************************************************************
  20. *                               C                                    *
  21. **********************************************************************
  22. *                  COPYRIGHT 1983 EUGENE H. MALLORY                  *
  23. *********************************************************************/
  24. #include "BDSCIO.h"
  25. #define BCOUNT 200
  26. char string[MAXLINE];
  27. char fname[MAXLINE], fname2[MAXLINE];
  28. char c;
  29. int fd1, fd2;
  30. FILE fcb1;
  31. char barray[BCOUNT][MAXLINE];
  32. char buffer[128];
  33. int bctr, flag;
  34. main(argc, argv)
  35. char **argv;
  36. int argc;
  37. {
  38.     char *n, fname[MAXLINE];
  39.     FILE fcb;
  40.     int i, j, len, flag;
  41.     if (argc == 1)
  42.     {
  43.         if (fopen("CNAME.$$$", fcb) == -1)
  44.         {
  45.             printf("E: Unable to open file CNAME.$$$.\n");
  46.             exit(0);
  47.         }
  48.         fgets(fname, fcb);
  49.         fname[strlen(fname) - 1] = 0;
  50.         strcpy(fname2, fname);
  51.         for (i = argc - 2; i > 0; i--)
  52.             argv[i + 1] = argv[i];
  53.         argv[1] = fname2;
  54.         argc++;
  55.         fclose(fcb);
  56.         printf("  C %s\n", argv[1]);
  57.     }
  58.     if (argc >= 2)
  59.     {
  60.         fcreat("CNAME.$$$", fcb);
  61.         fputs(argv[1], fcb);
  62.         fputs("\n\032", fcb);
  63.         fflush(fcb);
  64.         fclose(fcb);
  65.         strcpy(fname, argv[1]);
  66.     }
  67.  
  68.     strcat(fname, ".C");
  69.  
  70.     fd1 = fopen(fname, fcb1);
  71.     if (fd1 == ERROR)
  72.     {
  73.         printf("C: Cannot open file %s.\n", fname);
  74.         exit(0);
  75.     }
  76.     flag = bctr = 0;
  77.     while (fgets(string, fcb1))
  78.     {
  79.         len = strlen(string);
  80.         string[len - 1] = 0;
  81.         if (string[0] == '%')
  82.         {
  83.             flag = 1;
  84.             linecopy(barray[bctr++], &string[1], argv, argc, 0);
  85.         }
  86.         else
  87.             if (flag == 1)
  88.             break;
  89.         if (bctr == BCOUNT)
  90.         {
  91.             printf("C: Batch file too big.");
  92.             exit(0);
  93.         }
  94.     }
  95.     /*    SUBSTITUTED ARGUMENTS ARE NOW IN BARRAY */
  96.  
  97. writesub :
  98.     fd2 = open("A:$$$.SUB", 2);
  99.     if (fd2 == -1)
  100.     {
  101.         fd2 = creat("A:$$$.SUB");
  102.     }
  103.     else
  104.     {
  105.         do
  106.             {
  107.             flag = read(fd2, buffer, 1);
  108.             if (flag == -1)
  109.             {
  110.                 printf("C: Unable to append to A:$$$.SUB.");
  111.                 exit(0);
  112.             }
  113.         }
  114.         while (flag)
  115.             ;
  116.     }
  117.     /* Now $$.sub should be opened correctly */
  118.     while (bctr--)
  119.     {
  120.         for (i = 0; i < 128; i++)
  121.             buffer[i] = 0x1a;
  122.         strcpy(&buffer[1], barray[bctr]);
  123.         buffer[0] = strlen(barray[bctr]);
  124.         i = write(fd2, buffer, 1);
  125.         if (i != 1)
  126.         {
  127.             printf("%S: Unable to write A:$$$.SUB.", argv[0]);
  128.             exit(0);
  129.         }
  130.     }
  131.     close(fd2);
  132.     bios(1);
  133. }
  134.  
  135. linecopy(dest, source, argv, argc, bias)
  136. char *dest, *source, **argv;
  137. int argc, bias;
  138. {
  139.     int i;
  140.     char c, tempstr[MAXLINE];
  141.     if (*source == '*')
  142.         *source = ';';
  143.     while (c = *source++)
  144.     {
  145.         if (c == '$' && isdigit(*source))
  146.         {
  147.             i = *source - '0' + bias;
  148.             if (i < argc)
  149.             {
  150.                 strcpy(dest, argv[i]);
  151.                 dest += strlen(argv[i]);
  152.             }
  153.             source++;
  154.         }
  155.         else
  156.             if (c == '$' && *source == '*')
  157.         {
  158.             for (i = 1 + bias; i < argc; i++)
  159.             {
  160.                 if (i < argc)
  161.                 {
  162.                     strcpy(dest, argv[i]);
  163.                     strcat(dest, " ");
  164.                     dest += strlen(argv[i]) + 1;
  165.                 }
  166.             }
  167.             source++;
  168.         }
  169.         else
  170.             if (c == '$' && *source == '#')
  171.         {
  172.             sprintf(tempstr, "%d", argc - bias);
  173.             strcpy(dest, tempstr);
  174.             dest += strlen(tempstr);
  175.             source++;
  176.         }
  177.         else
  178.             if (c == '$' && *source == '$')
  179.         {
  180.             source++;
  181.             *dest++ = c;
  182.         }
  183.         else
  184.             if (c == '^' && isalpha(*source))
  185.         {
  186.             *dest++ = toupper(*source) - 0x40;
  187.             source++;
  188.         }
  189.         else
  190.             {
  191.             *dest++ = c;
  192.         }
  193.     }
  194.     *dest = 0;
  195. }
  196.  
  197.